package com.mysite.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mysite.mapper.UserMapper;
import com.mysite.po.User;

@Service
public class UserService {

	@Autowired
	private UserMapper mapper;

	public boolean doLogin(User u) {
		int count = mapper.checkUser(u);
		return count != 0;
	}

	public List<User> getUsers(String searchText) {
		Map<String, Object> map = new HashMap<>();
		map.put("searchText", searchText);
		return mapper.getUsersByCondition(map);
	}

	public boolean addUser(User user) {
		int result = mapper.insertUser(user);
		return result == 1;
	}

	public boolean delUser(int id) {
		int result = mapper.deleteUser(id);
		return result == 1;
	}
}
